﻿@using System.Collections
@model MMSWebsite.Models.EmployeeViewModel

    <table >
        <tr>
            <td class="tdLeft"> @Html.LabelFor(model => model.Employee.Code)</td>
            <td class="tdRight"> @Html.EditorFor(model => model.Employee.Code)
                @Html.ValidationMessageFor(model => model.Employee.Code)
            </td>
        </tr>
       @* <tr>
            <td class="tdLeft"> @Html.LabelFor(model => model.Employee.Password)</td>
            <td class="tdRight"> @Html.EditorFor(model => model.Employee.Password) 
                @Html.ValidationMessageFor(model => model.Employee.Password)</td>
        </tr>*@
        <tr>
            <td class="tdLeft" > @Html.LabelFor(model => model.Employee.Name)</td>
            <td class="tdRight"> @Html.EditorFor(model => model.Employee.Name)
                @Html.ValidationMessageFor(model => model.Employee.Name)</td>
        </tr>
        <tr>
            <td class="tdLeft"> @Html.LabelFor(model => model.Employee.IdCode)</td>
            <td class="tdRight"> @Html.EditorFor(model => model.Employee.IdCode)
                @Html.ValidationMessageFor(model => model.Employee.IdCode)</td>
        </tr>
        <tr>
            <td class="tdLeft"> @Html.LabelFor(model => model.Employee.Sex)</td>
            <td class="tdRight"> @Html.EditorFor(model => model.Employee.Sex)
                @Html.ValidationMessageFor(model => model.Employee.Sex)</td>
        </tr>
        <tr>
            <td class="tdLeft"> @Html.LabelFor(model => model.Employee.Email)</td>
            <td class="tdRight"> @Html.EditorFor(model => model.Employee.Email)
                @Html.ValidationMessageFor(model => model.Employee.Email)</td>
        </tr>
        <tr>
            <td class="tdLeft"> @Html.LabelFor(model => model.Employee.Phone)</td>
            <td class="tdRight"> @Html.EditorFor(model => model.Employee.Phone)
                @Html.ValidationMessageFor(model => model.Employee.Phone)</td>
        </tr>
        <tr>
            <td class="tdLeft"> @Html.LabelFor(model => model.Employee.Birth)</td>
            <td class="tdRight"> @Html.EditorFor(model => model.Employee.Birth)
                @Html.ValidationMessageFor(model => model.Employee.Birth)</td>
        </tr>
        <tr>
            <td class="tdLeft"> @Html.Label("Address")</td>
            <td class="tdRight">
                <table >
                    <tr>
                        <td class="tdLeft">  Number Address</td>
                        <td class="tdRight"> @Html.EditorFor(model => model.Employee.NumberAddress) </td>
                    </tr>
                    <tr>
                        <td class="tdLeft">  City</td>
                        <td class="tdRight"> @Html.DropDownListFor(model => model.Employee.Area.CityName, new SelectList(ViewBag.Cities as IEnumerable), string.Empty)
                            @Html.ValidationMessageFor(model => model.Employee.Area.CityName) </td>
                    </tr>
                    <tr>
                        <td class="tdLeft">  District</td>
                        <td class="tdRight">  @Html.DropDownListFor(model => model.Employee.Area.DistrictName, new SelectList(ViewBag.Districts as IEnumerable), string.Empty)
                                @Html.ValidationMessageFor(model => model.Employee.Area.DistrictName) </td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr >
        <td class="tdLeft">@Html.Label("Set Roles To User") </td>
        <td class="tdRight" >
            @foreach (var role in Model.Roles)
            {
                <input type="checkbox" id="@role.Role.Id" name="@role.Role.RoleName" @(role.RoleIsChecked ? "checked" : "") />
                @role.Role.RoleName
                <br/>
            }
        </td>
        <tr>
        <tr>
            <td  class = "tdRight" colspan="2" style="text-align: center">
                <input type="button" value="Reset Password" onclick="location.href = '@Url.Action("ResetPassword", "Employee", new {id = Model.Employee.Id})'" />
                <input type="submit" value="Save Employee"> 
                @if (Model.Employee.Name != null)
                {
                    <input type="button" value="Lock this employee" onclick="location.href = '@Url.Action("TriggerLock", "Employee", new {id = Model.Employee.Id})'" />
                }
            </td>
           
        </tr>
    </table>

<script type="text/javascript">

    //Set Code Field Is Disable
    $(document).ready(function () {
        $('#@Html.IdFor(model=>model.Employee.Code)').attr("readonly", true);
    });
    
    //Cascading dropdownlist city and district
    var selector = {
        City: "select#@Html.IdFor(model => model.Employee.Area.CityName)",
        District: "select#@Html.IdFor(model => model.Employee.Area.DistrictName)"
    };

    $(selector.City).change(function () {
        selectFromAjax('@Url.Action("DistrictList", "Employee")', { city: $(this).find("option:selected").val() }, $(selector.District));
        console.log($(this).find("option:selected").val());
    });

</script>
  
